# -*- coding: utf-8 -*-
"""
Created on 2021-08-16 22:35:16

@author: 王佳佳
"""

import numpy as np
# Using daltonize-0.1.0, see https://github.com/joergdietrich/daltonize
from daltonize import daltonize as dz
from PIL import Image


def img2rgb(img_file):
    """Convert image to rgb array

    Parameters
    ----------
    img_file : str
        Filepath of png or jpg image

    Returns
    -------
    np.array
        np.array of shape (M, N, 3) representing rgb of image
    """
    return np.array(Image.open(img_file).convert('RGB'))

def colorblind_img(img_file, colorblind_type="d"):
    """Simulate the effect of color blindness on an image.
    (What a colorblind person sees the image as)

    Parameters
    ----------
    img_file : str
        Filepath of original image

    colorblind_type : One of {"d", "p", "t"}, optional
        type of colorblindness, d for deuteronopia (default),
        p for protonapia,
        t for tritanopia

    Returns
    -------
    PIL Image
        simulated image as a PIL Image
    """
    rgb_arr = img2rgb(img_file)
    cb_arr = dz.simulate(rgb_arr, color_deficit=colorblind_type).astype('uint8')
    cb_img = Image.fromarray(cb_arr)
    return cb_img


# img = Image.open('./tomCat.png')
img = colorblind_img('./tomCat.png')
img.show()